﻿
#region Using Directives

    using System;
    using System.Text;

#endregion

namespace MarketPulse.BusinessLogic.Private.StateMachine
{
    /// <summary>
    /// Exception thrown when an attempt is made to transition to
    /// a new state where that transition is invalid.  
    /// </summary>
    [Serializable]
    public class AssignmentStateTransitionException : Exception
    {
        /// <summary>
        /// The current visit state
        /// </summary>
        protected string mFromState;

        /// <summary>
        /// The event or transition attempted
        /// </summary>
        protected string mAction;

        /// <summary>
        /// The error message to be emitted later
        /// </summary>
        protected string mMessage;

        /// <summary>
        /// Constructs a new AssignmentStateTransitionException using the supplied arguments
        /// </summary>
        /// <param name="fromState">The current visit state</param>
        /// <param name="action">The erroneous event/transition</param>
        public AssignmentStateTransitionException(string fromState, string action)
        {
            mFromState = fromState;
            mAction = action;
            StringBuilder sb = new StringBuilder();
            sb.Append("Unable to perform [ ");
            sb.Append(mAction);
            sb.Append(" ] on visit when in [ ");
            sb.Append(mFromState);
            sb.Append(" ] state ");
            mMessage = sb.ToString();
        }

        /// <summary>
        /// Message property overridden from Exception
        /// </summary>
        public override string Message
        {
            get
            {
                return mMessage;
            }
        }
    }
}
